package com.groupbuying.currency.producer.controller;

import com.groupbuying.currency.producer.domain.CurrencyActivityDO;
import com.groupbuying.currency.producer.service.CurrencyActivityService;
import com.groupbuying.currency.producer.utils.JSONUtils;
import com.groupbuying.currency.producer.utils.PageUtils;
import com.groupbuying.currency.producer.utils.Query;
import com.groupbuying.currency.producer.utils.R;
import com.groupbuying.currency.producer.utils.currencyOperUtils.ParamUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 积分活动表
 *
 * @author ywxd
 * @email yuwenxiaodong@126.com
 * @date 2019-04-15 17:20:46
 */

@RestController
@RequestMapping("/currencyActivity")
public class CurrencyActivityController {
    @Autowired
    private CurrencyActivityService currencyActivityService;

    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<CurrencyActivityDO> currencyActivityList = currencyActivityService.list(query);
        int total = currencyActivityService.count(query);
        PageUtils pageUtils = new PageUtils(currencyActivityList, total);
        return pageUtils;
    }

    /**
     * 保存
     */
    @ResponseBody
    @PostMapping("/save")
    public R save(CurrencyActivityDO currencyActivity) {
        if (currencyActivityService.save(currencyActivity) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    public R update(CurrencyActivityDO currencyActivity) {
        currencyActivityService.update(currencyActivity);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @ResponseBody
    public R remove(String activityId) {
        if (currencyActivityService.remove(activityId) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 用户积分充值入口
     */
    @ApiOperation(value = "用户积分充值入口", notes = "用户积分充值入口")
    @PostMapping("/customerAdd")
    @ResponseBody
    public R customerAdd(@RequestParam Map<String, Object> params) {
        return currencyActivityService.addCustomerCurrency(params);
    }


    /**
     * 平台积分充值入口
     */
    @ApiOperation(value = "平台积分充值入口", notes = "平台积分充值入口")
    @PostMapping("/platformAdd")
    @ResponseBody
    public R platformAdd(@RequestParam Map<String, Object> params) {
        return currencyActivityService.addPlatformCurrency(params);
    }

}
